package main

import "fmt"

func main() {
	ch := make(chan int)
	quit := make(chan bool)

	go fibonacci2(ch, quit)

	x, y := 1, 1
	for i := 0; i <= 20; i++ {
		ch <- x
		x, y = y, x+y

	}
	quit <- true
}

func fibonacci2(ch <-chan int, quit <-chan bool) {
	for {
		select {
		case y:=<-ch:
			fmt.Println(y)
		case <-quit:
			fmt.Println("end")
			return
		}
	}
}
